import testlink
import re

test_url= "http://192.168.0.201/testlink/lib/api/xmlrpc/v1/xmlrpc.php"
test_key = "a695a58b5cde364a3a669bac4302054a"
tlc = testlink.TestlinkAPIClient(test_url, test_key)

def get_suiteid():
    list_1 = []
    list_2 = []
    projects = tlc.getProjects()
    # print(projects)
    for i in projects:
        list_1.append(i['id'])
        list_2.append(i['name'])
    # print(list_1)
    # print(list_2)
    #['7739', '1', '20166', '77765', '259106', '133652', '225616', '40753', '106722', '68331', '64172', '165702', '210201', '294331']
    #['BB02', 'BB03fpga', 'BB04fpga', 'BB04P', 'BB04P1', 'BB04P2fpga', 'BB04P4fpga', 'BB04Pfpga', 'BB04Pxfpga', 'NB01P', 'NB01POLD', 'NB01PP', 'test', 'WTM2102fpga']

First_suites = tlc.getFirstLevelTestSuitesForTestProject('210201')
#312036,309561,305644,341048,316249,326813,355470,322132,295657 一级目录ID
# print(First_suites[0])
#{'id': '312036', 'parent_id': '294331', 'node_type_id': '2', 'node_order': '0', 'node_table': 'testsuites', 'name': 'UART1_pin 2.3'}

suite_case_id = tlc.getTestCasesForTestSuite(testsuiteid='312031', deep=True, details='only_id') #二级的ip信息
# print(suite_case)
# for i in suite_case:
#     print(i)
#[{'id': '313729', 'parent_id': '312783', 'node_type_id': '3', 'node_order': '0', 'node_table': 'testcases', 'name': 'RAM to uart case1test', 'external_id': 'WTM2102fpga-2531'}, 

all_thing = tlc.getTestCase('313729')
# print(all_thing)
#{'updater_login': 'yeyinqin', 'author_login': 'yeyinqin', 'name': 'RAM to uart case1test', 'node_order': '0', 'testsuite_id': '312783', 'testcase_id': '313729', 
# 'id': '313730', 'tc_external_id': '2531', 'version': '1', 'layout': '1', 'status': '1', 'summary': '<p>用于测试UART1 pin 2.3(复用功能3)模式下,默认波特率
#  pin03 open mode_output mux_mode0', 'expected_results': '', 'active': '1', 'execution_type': '2'}, {'id': '313736', 'step_number': '6', 'actions':
#  'uart uart1 close', 'expected_results': '', 'active': '1', 'execution_type': '2'}, {'id': '313737', 'step_number': '7', 'actions':
#  'gpio pin02 pin03 open mode_output mux_mode3', 'expected_results': '', 'active': '1', 'execution_type': '2'}, 

# print(all_thing[0]['summary'])
# <p>用于测试UART1 pin 2.3(复用功能3)模式下,默认波特率在115200下，在开DMA配置下,开关FIFO数据发送</p>
# list_3 = []
# for i in suite_case:
#     one_piece = tlc.getTestCase(i)
#     # print(one_piece[0]['summary'])
#     list_3.append(one_piece[0]['summary'])
    #'<p>用于测试UART1 pin 2.3(复用功能3)模式下,默认波特率在115200下，在开DMA配置下,开关FIFO数据发送</p>\n', '<p>用于测试UART1(复用功能3)模式下,默认波特率在115200下，在开DMA配置下,开关FIFO数据接收
# print(list_3)
    # all_thing_1 = tlc.getTestCase(i['id'])
    # print(all_thing_1)

dic = []
for j in suite_case_id:
    list4_dic = {}
    one_piece = tlc.getTestCase(j)
    data = one_piece[0]['summary']
    data = data.replace('</p>', '')
    data = data.replace('<p>', '')
    data = data.replace('UART1','UART0')
    list4_dic['ID'] = j
    list4_dic['summary'] = data
    dic.append(list4_dic)
    print(dic)
    # print(data)
    # list4.append(data)

for i in dic:
    tlc.updateTestCase(testcaseid=i['ID'], summary = i['summary'],)



# for i in suite_case:
#     list_3.append(i['id'])




# Second_suites = 



# def deliver_data_to_testlink(data):











if __name__ == '__main__':
    get_suiteid()